package com.uhuibao.tmall.common.utils;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * 框架本身的用户密码加密跟卡管理的不一致，重写一下
 * @author huangzj
 */
@Component
public class MyPasswordEncoder implements PasswordEncoder {
    /**
     * 重写加密方法，采用跟卡管理一致
     *
     * @param charSequence
     * @return
     */
    @Override
    public String encode(CharSequence charSequence) {
        String password = charSequence.toString();
//        SYDESencrypt des = new SYDESencrypt();
//        System.out.println("加密后密码："+des.Encrypt(password));
        return password;
    }


    /**
     * @param charSequence 前端传过来的明文密码
     * @param s            数据库中存储的密文密码
     * @return
     */
    @Override
    public boolean matches(CharSequence charSequence, String s) {
        String password = charSequence.toString();
//        System.out.println("数据库密码："+s);
//        System.out.println("原始密码："+charSequence.toString());
//        System.out.println("比对密码："+password);
        return password.equals(s);
    }
}